const arr = [1, 2, 3, 4, 5]

const _map = (arr, fn) => {
  return arr.reduce((mappedArr, el) => {
    return [...mappedArr, fn(el)]
  }, [])
}
let mappedArr = _map(arr, el => el + 1)
console.log(mappedArr)

const _filter = (arr, fn) => {
  return arr.reduce((filteredArr, el) => {
    return fn(el) ? [...filteredArr, el] : filteredArr
  }, [])
}
let filteredArr = _filter(arr, el => el & 1)
console.log(filteredArr)

const _flatDeep = arr => {
  return arr.reduce((flattenArr, el) => {
    return Array.isArray(el)
      ? [...flattenArr, ..._flatDeep(el)]
      : [...flattenArr, el]
  }, [])
}
// test
let flattenArr = [[1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]
flattenArr = _flatDeep(flattenArr)
console.log(flattenArr)
